<?php

namespace App\Http\Controllers\Api\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Auth;
use App\Exceptions\ValidateParameterException;
use App\Facades\Utils\LogUtil;
use App\Facades\Services\AccountService;

class CustomerController extends Controller
{
	/*
	登录
	 */
    public function login(Request $request){

        $data = $request->all();

        if (!Auth::attempt(['uname' => $data['uname'], 'password' => $data['password']])) {
            throw new ValidateParameterException('您的账号或者密码错误，请重新输入');
        }

        LogUtil::loginLog(Auth::user()->name);

        return formatJsonResponse();
    }

    /*
    登出
     */
    public function logout(Request $request){

    	$userName = Auth::user()->name;

    	Auth::logout();

    	LogUtil::logoutLog($userName);

    	return formatJsonResponse();
    }

    /*
    创建用户
     */
    public function create(Request $request){

    	AccountService::create($request);

    	return formatJsonResponse();
    }

    /*
    删除用户
     */
    public function delete(Request $request){

    	AccountService::delete($request);

    	return formatJsonResponse();
    }

    /*
    修改密码
     */
    public function updatePassword(Request $request){

    	AccountService::updatePassword($request);

    	return formatJsonResponse();
    }

    public function updateInfo(Request $request){

        AccountService::update($request);

        return formatJsonResponse();
    }
}
